import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import os
import folium as fol
from scipy.spatial import Voronoi, voronoi_plot_2d
import geohash as gh

import data_process as dp
from sklearn.neighbors import KNeighborsClassifier as KNN

# 将数据按照要求读入
from mpl_toolkits.mplot3d import Axes3D

data = pd.read_csv('mobike_shanghai.csv', usecols=['orderid',
                                                   'bikeid',
                                                   'userid',
                                                   'start_time',
                                                   'start_location_x', 'start_location_y',
                                                   'end_time',
                                                   'end_location_x', 'end_location_y',
                                                   'track'])

# 对读入的信息进行基本操作


# 使用geohash编码start_location和end_location，并把它们存到start_location_geohash和end_location_geohash中
# data['start_location_geohash'] = data['start_location'].apply(lambda x: gh.encode(x[1], x[0], precision=7))
# data['end_location_geohash'] = data['end_location'].apply(lambda x: gh.encode(x[1], x[0], precision=7))

# 删除start_location_x小于121，start_location_x大于121.8，start_location_y小于30.94的数据，并统计删除元素的个数
data_len = len(data)
data = data[(data['start_location_x'] > 121.1) & (data['start_location_x'] < 121.8)]
data = data[(data['end_location_x'] > 121.1) & (data['end_location_x'] < 121.8)]
print("删除元素个数：", data_len - len(data))

# 读入start_location_x和start_location_y，并把它存到start_location中
data['start_location'] = data[['start_location_x', 'start_location_y']].apply(lambda x: (x[0], x[1]), axis=1)

# 读入end_location_x和end_location_y，并把它存到end_location中
data['end_location'] = data[['end_location_x', 'end_location_y']].apply(lambda x: (x[0], x[1]), axis=1)

# 把start_location和end_location中的坐标数据都转换为小数点后3位的浮点数
data['start_location'] = data['start_location'].apply(lambda x: (round(x[0], 3), round(x[1], 3)))
data['end_location'] = data['end_location'].apply(lambda x: (round(x[0], 3), round(x[1], 3)))
# 得到按时间划分后的数据
dp.get_date_divided_data(data)

# 将数据按升序排序
dp.sort_csv_in_folder('processed_data')

# 将数据再次细分
dp.data_slice_in_folder('processed_data')







































